package com.hxm.appGenealogy.controller;
import com.hxm.appGenealogy.config.duanxinfuwu.SmsClientSend;
import com.hxm.appGenealogy.entity.People;
import com.hxm.appGenealogy.entity.ResponDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.concurrent.TimeUnit;

/**
 * 短信发送实体类;
 */
@CrossOrigin
@RestController
@RequestMapping("app/note")
public class NoteController {
    @Autowired
    private RedisTemplate<String , Object> stringRedisTemplate;


    @Value("${hxm.duanxin.sendsmsurl}")
    private String sendsmsurl;

    @Value("${hxm.duanxin.account}")
    private String account;

    @Value("${hxm.duanxin.password}")
    private String password;

    @PostMapping("ym")
    public ResponDataVo getNote(@RequestBody People people){
        Integer yanzhengma = (int) ((Math.random() * 9 + 1) * 10000);
        System.out.println(yanzhengma);
        String pref = "李文倩吃小鸡";
        //发送短信  //【琉珖塔科技】验证码:"+yanzhengma+"，有效期5分钟，请勿向他人泄露
        SmsClientSend.sendSms(sendsmsurl,account,password,people.getNumber(),"【琉珖塔科技】验证码:"+yanzhengma+"，有效期5分钟，请勿向他人泄露");
        stringRedisTemplate.opsForValue().set(people.getNumber(),yanzhengma.toString(),300, TimeUnit.SECONDS);
        //String o = (String)stringRedisTemplate.opsForValue().get(people.getNumber());
        return new ResponDataVo("发送验证码成功;");
    }

}
